﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class export_teacherExport : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string teacher_id = "";
        string teacher_name = "";

        System.Data.DataTable table1 = new System.Data.DataTable();
        int count = 0;//总记录的条数
        try
        {
            //填充数据
            
            if (Request.QueryString["teacher_id"] != null)
            {
                teacher_id = Request.QueryString["teacher_id"].ToString().Trim();
            }
            if (Request.QueryString["teacher_name"] != null)
            {
                teacher_name = Request.QueryString["teacher_name"].ToString().Trim();
            }

            
            List<string> wheres = new List<string>();
            if (teacher_id != "")
            {
                wheres.Add("teacher_id like '%" + teacher_id + "%'");
            }
            if (teacher_name != "")
            {
                wheres.Add("teacher_name like '%" + teacher_name + "%'");
            }
            string wh = "";
            if (wheres.Count > 0)
            {
                wh = string.Join(" and ", wheres.ToArray());
                
            }
            
            
            string sql = "select  a.teacher_id ,a.teacher_name ,b.college_name, a.teacher_tel from tb_teacher as a "
                     + " inner join tb_college as b on a.college_id = b.college_id ";

            if (wheres.Count > 0)
            {
                sql = sql + " where " + wh ;
            }
            
            table1 = SqlServer.GetDataTable(sql);
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('有错误')</script>");
            Response.End();
        }
        Response.Write(Json.ToJson(table1, count));
        Response.End();

    }

}